package com.liy.cloud.common.trade.entity;

import com.liy.cloud.common.exception.NegativeNumberException;
import com.liy.cloud.common.trade.utils.TradeMessageParser;
import com.das.framework.common.exception.BusinessException;

import java.io.Serializable;
import java.text.ParseException;

/**
 * 行政类数据明细表实体类
 * 作者: 
 * 日期：2018-08-12 17:14:37
 * 描述：
 */
public class TradeAdmin extends TradeComm implements Serializable{

	private static final long serialVersionUID = 1L;
	  
    /*
     * 主表ID
     */
    private String commId;
    
    /*
     * 审核人ID
     */
    private String operId;
    
    /*
     * 行政类原因
     */
    private String dealReason;
    
    /*
     * 行政原因描述
     */
    private String describe;
    
    /*
     * 计费方式
     */
    private String billType;
    
    /*
     * 故障设备编号
     */
    private String faultDid;
    
    /*
     * 故障时间
     */
    private String faultTime;
    
    /*
     * 故障票卡单价
     */
    private Long faultPrice;
    
    /*
     * 相关票卡卡号
     */
    private String relateCardId;
    
    /*
     * 卡票数量
     */
    private Long ticketStopNum;
    
    /*
     * 交易类型编码
     */
    private String tradeCode;
    
    
    
    /**
     * 默认构造方法
     **/
    public TradeAdmin(){
      super();
    }
    
    /** 
     * getger和setter方法
     */
    
    public String getCommId(){
      return commId;
    }
    public void setCommId(String commId){
      this.commId=commId;
    }
    
    public String getOperId(){
      return operId;
    }
    public void setOperId(String operId){
      this.operId=operId;
    }
    
    public String getDealReason(){
      return dealReason;
    }
    public void setDealReason(String dealReason){
      this.dealReason=dealReason;
    }
    
    public String getDescribe(){
      return describe;
    }
    public void setDescribe(String describe){
      this.describe=describe;
    }
    
    public String getBillType(){
      return billType;
    }
    public void setBillType(String billType){
      this.billType=billType;
    }
    
    public String getFaultDid(){
      return faultDid;
    }
    public void setFaultDid(String faultDid){
      this.faultDid=faultDid;
    }
    
    public String getFaultTime(){
      return faultTime;
    }
    public void setFaultTime(String faultTime) throws ParseException{
    	checkTimeStyle(faultTime, "FaultTime");
      this.faultTime=faultTime;
    }
    
    public Long getFaultPrice(){
      return faultPrice;
    }
    public void setFaultPrice(Long faultPrice) throws NegativeNumberException {
    	checkMoneyStyle(faultPrice, "FaultPrice");
      this.faultPrice=faultPrice;
    }
    
    public String getRelateCardId(){
      return relateCardId;
    }
    public void setRelateCardId(String relateCardId){
      this.relateCardId=relateCardId;
    }
    
    public Long getTicketStopNum(){
      return ticketStopNum;
    }
    public void setTicketStopNum(Long ticketStopNum) throws NegativeNumberException{
    	
    	checkNumberStyle(ticketStopNum, "TicketStopNum");
      this.ticketStopNum=ticketStopNum;
    }
    
    public String getTradeCode(){
      return tradeCode;
    }
    public void setTradeCode(String tradeCode){
      this.tradeCode=tradeCode;
    }
    
    
    /**
     * 根据版本容解析交易内容
     * @param message
     * @throws Exception 
     * @throws BusinessException 
     */
	public TradeAdmin init(String message) throws Exception {

        TradeMessageParser messageParser = null;
        if(message.startsWith("SZMETROV2")) {

            // 根据报文格式长度来定义， -1为行业分割符
            int[] splitNumber = {
                    9, 8, 9, 2, 10,		9, 6, 6, 14, 10,	8, 8, 8, 5, 10,		2, 30, 1, 20, 10,
                    2, 2, 16, 1, 1,		9, 14, 8, 20, 2,	1, 4, 5, -1, 5
            };

            messageParser = new TradeMessageParser(message, splitNumber);
			this.setVersion(messageParser.getFiled(0));
			this.setTac(messageParser.getFiled(1));
			this.setCardId(messageParser.getFiled(2));
			this.setTradeCode(messageParser.getFiled(3));
			this.setTradeAddress(messageParser.getFiled(4));
			
			this.setDeviceId(messageParser.getFiled(5));
			this.setOperator(messageParser.getFiled(6));
			this.setOperId(messageParser.getFiled(7));
			this.setTradeTime(messageParser.getFiled(8));
			this.setDeviceSeq(Long.parseLong(messageParser.getFiled(9)));
			
			this.setTradeMoney(Long.parseLong(messageParser.getFiled(10)));
			this.setTradeValue(Long.parseLong(messageParser.getFiled(11)));
			this.setCost(Long.parseLong(messageParser.getFiled(12)));	//费用
			this.setCardSeq(Long.parseLong(messageParser.getFiled(13)));
			this.setDeviceSum(Long.parseLong(messageParser.getFiled(14)));
			
			this.setDealReason(messageParser.getFiled(15));
			this.setDescribe(messageParser.getFiled(16));
			this.setBillType(messageParser.getFiled(17));
			this.setSamcardId(messageParser.getFiled(18));
			this.setSamcardSeq(Long.parseLong(messageParser.getFiled(19)));
			
			this.setCardCode(messageParser.getFiled(20));
			this.setTradeSub(messageParser.getFiled(21));
			this.setPhysicalId(messageParser.getFiled(22));
			this.setTestFlag(messageParser.getFiled(23));
			this.setGreyFlag(messageParser.getFiled(24));
			
			this.setFaultDid(messageParser.getFiled(25));
			this.setFaultTime(messageParser.getFiled(26));
			this.setFaultPrice(Long.parseLong(messageParser.getFiled(27)));
			this.setRelateCardId(messageParser.getFiled(28));
			this.setTicketStopNum(Long.parseLong(messageParser.getFiled(29)));
			
			this.setIndustrySplit(messageParser.getFiled(30));
			this.setIssuer(messageParser.getFiled(31));
			super.setIndustryDataLength(Long.parseLong(messageParser.getFiled(32)));
			super.setIndustryData(messageParser.getFiled(33));
			super.setCrc16(messageParser.getFiled(34));

        } else if(message.startsWith("SZMETROV3")) {

            /** 根据报文格式长度来定义， -1为行业分割符
             * 一、V3卡号由9位变为20位
             * 二、增加字段：
             付费方式
             支付方式
             发卡方机构码
             发卡方交易流水号
             运营模式
             三、票卡发行方标识	从长度4变为长度2
             */
            int[] splitNumber = {
                    9, 8, 20, 2, 10,		9, 6, 6, 14, 10,	8, 8, 8, 5, 10,		2, 30, 1, 20, 10,   2, 2, 16, 1, 1,		9, 14, 8, 20, 2,
                    1, 2, 8, 10, 4,    //V3增加的字段
                    1, 2, 5,
                    -1, 5};
            messageParser = new TradeMessageParser(message, splitNumber);
            this.setVersion(messageParser.getFiled(0));
            this.setTac(messageParser.getFiled(1));
            this.setCardId(messageParser.getFiled(2));
            this.setTradeCode(messageParser.getFiled(3));
            this.setTradeAddress(messageParser.getFiled(4));

            this.setDeviceId(messageParser.getFiled(5));
            this.setOperator(messageParser.getFiled(6));
            this.setOperId(messageParser.getFiled(7));
            this.setTradeTime(messageParser.getFiled(8));
            this.setDeviceSeq(Long.parseLong(messageParser.getFiled(9)));

            this.setTradeMoney(Long.parseLong(messageParser.getFiled(10)));
            this.setTradeValue(Long.parseLong(messageParser.getFiled(11)));
            this.setCost(Long.parseLong(messageParser.getFiled(12)));	//费用
            this.setCardSeq(Long.parseLong(messageParser.getFiled(13)));
            this.setDeviceSum(Long.parseLong(messageParser.getFiled(14)));

            this.setDealReason(messageParser.getFiled(15));
            this.setDescribe(messageParser.getFiled(16));
            this.setBillType(messageParser.getFiled(17));
            this.setSamcardId(messageParser.getFiled(18));
            this.setSamcardSeq(Long.parseLong(messageParser.getFiled(19)));

            this.setCardCode(messageParser.getFiled(20));
            this.setTradeSub(messageParser.getFiled(21));
            this.setPhysicalId(messageParser.getFiled(22));
            this.setTestFlag(messageParser.getFiled(23));
            this.setGreyFlag(messageParser.getFiled(24));

            this.setFaultDid(messageParser.getFiled(25));
            this.setFaultTime(messageParser.getFiled(26));
            this.setFaultPrice(Long.parseLong(messageParser.getFiled(27)));
            this.setRelateCardId(messageParser.getFiled(28));
            this.setTicketStopNum(Long.parseLong(messageParser.getFiled(29)));

            // V3增加字段
            this.setPayMethod(messageParser.getFiled(30));
            this.setPayType(messageParser.getFiled(31));
            this.setIssuerCode(messageParser.getFiled(32));
            this.setIssuerSeq(messageParser.getFiled(33));
            this.setOperMode(messageParser.getFiled(34));

            this.setIndustrySplit(messageParser.getFiled(35));
            this.setIssuer(messageParser.getFiled(36));
            super.setIndustryDataLength(Long.parseLong(messageParser.getFiled(37)));
            super.setIndustryData(messageParser.getFiled(38));
            super.setCrc16(messageParser.getFiled(39));
        }
		
		return this;
	}

}                    